<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class M_tholabah extends CI_Controller {

	function __construct() {
        parent::__construct();	
        $this->load->model("master/master_j_pendidikan"); 
        $this->load->model("master/master_pendidikan"); 
		$this->load->model("master/master_pekerjaan");
		$this->load->model("master/master_tholabah");
	}
	
	function index()
	{
		$data['judul'] = "Master Tholabah";
		$data['list'] = $this->master_j_pendidikan->read();
		$data['main_view']='master/tholabah/j_pendidikan';
		$this->load->view('index',$data);
		
	}

	function tholabah($id_m_j_pendidikan)
	{
		$data['judul'] = "Master Tholabah";
		$data['list'] = $this->master_tholabah->tholabah($id_m_j_pendidikan);	
		$data['list_jp'] = $this->master_j_pendidikan->detail($id_m_j_pendidikan);
		$data['list_it'] = $this->master_pendidikan->read();
		$data['list_pk'] = $this->master_pekerjaan->read();	

		$data['main_view']='master/tholabah/tholabah';
		$this->load->view('index',$data);
	}

	function save()
	{
		$tgl_lahir = $this->input->post('tgl_lahir');
		$dateLahir = str_replace('/', '-', $tgl_lahir);
		$tglMySQLL = date('Y-m-d', strtotime($dateLahir));

		$tgl_reg = $this->input->post('tgl_reg');
		$dateReg = str_replace('/', '-', $tgl_reg);
		$tglMySQLR = date('Y-m-d', strtotime($dateReg));

		$dataInsert = array(
			'nama_lengkap' => $this->input->post('nama_lengkap'),
			'id_m_j_pendidikan' => $this->input->post('id_m_j_pendidikan'),
			// 'foto' => $this->input->post('foto'),
			'jk' => $this->input->post('jk'),
			'tmp_lahir' => $this->input->post('tmp_lahir'),
			'tgl_lahir' => $tglMySQLL,
			'anak_ke' => $this->input->post('anak_ke'),
			'jml_bersaudara' => $this->input->post('jml_bersaudara'),
			'ijazah_terakhir' => $this->input->post('ijazah_terakhir'),
			// 'lamp_ijazah' => $this->input->post('lamp_ijazah'),
			'alamat' => $this->input->post('alamat'),
			'nama_ayah' => $this->input->post('nama_ayah'),
			'kerja_ayah' => $this->input->post('kerja_ayah'),
			'no_tlp_ayah' => $this->input->post('no_tlp_ayah'),
			'nama_ibu' => $this->input->post('nama_ibu'),
			'kerja_ibu' => $this->input->post('kerja_ibu'),
			'no_tlp_ibu' => $this->input->post('no_tlp_ibu'),
			'alamat_ortu' => $this->input->post('alamat_ortu'),
			'tgl_reg' => $tglMySQLR
		);
		$this->master_tholabah->save($dataInsert);
	}

	function edit()
	{
		$id_m_tholabah = $this->input->post('id_m_tholabah');
		$id_m_j_pendidikan = $this->input->post('id_m_j_pendidikan');

		$data['list']=$this->master_tholabah->edit($id_m_tholabah);	
		$data['list_jp']=$this->master_j_pendidikan->detail($id_m_j_pendidikan);	
		$data['list_it'] = $this->master_pendidikan->read();
		$data['list_pk'] = $this->master_pekerjaan->read();	
		$this->load->view('master/tholabah/edit',$data);
	}

	function update()
	{	
		$tgl_lahir = $this->input->post('tgl_lahir');
		$dateLahir = str_replace('/', '-', $tgl_lahir);
		$tglMySQLL = date('Y-m-d', strtotime($dateLahir));

		$tgl_reg = $this->input->post('tgl_reg');
		$dateReg = str_replace('/', '-', $tgl_reg);
		$tglMySQLR = date('Y-m-d', strtotime($dateReg));

		$id_m_tholabah=$this->input->post('id_m_tholabah');
		$dataUpdate=array(
			'nama_lengkap' => $this->input->post('nama_lengkap'),
			//'id_m_j_pendidikan' => $this->input->post('id_m_j_pendidikan'),
			// 'foto' => $this->input->post('foto'),
			'jk' => $this->input->post('jk'),
			'tmp_lahir' => $this->input->post('tmp_lahir'),
			'tgl_lahir' => $tglMySQLL,
			'anak_ke' => $this->input->post('anak_ke'),
			'jml_bersaudara' => $this->input->post('jml_bersaudara'),
			'ijazah_terakhir' => $this->input->post('ijazah_terakhir'),
			// 'lamp_ijazah' => $this->input->post('lamp_ijazah'),
			'alamat' => $this->input->post('alamat'),
			'nama_ayah' => $this->input->post('nama_ayah'),
			'kerja_ayah' => $this->input->post('kerja_ayah'),
			'no_tlp_ayah' => $this->input->post('no_tlp_ayah'),
			'nama_ibu' => $this->input->post('nama_ibu'),
			'kerja_ibu' => $this->input->post('kerja_ibu'),
			'no_tlp_ibu' => $this->input->post('no_tlp_ibu'),
			'alamat_ortu' => $this->input->post('alamat_ortu'),
			'tgl_reg' => $tglMySQLR
		);		
		$this->master_tholabah->update($id_m_tholabah,$dataUpdate);
	}

	function delete()
	{
		$id_m_tholabah = $this->input->post('id_m_tholabah');
		$this->master_tholabah->delete($id_m_tholabah);
	}
	
	function refresh()
	{
		$id_m_j_pendidikan = $this->security->xss_clean($this->uri->segment(3));
		$data['list'] = $this->master_tholabah->tholabah($id_m_j_pendidikan);
		$data['list_jp']=$this->master_j_pendidikan->detail($id_m_j_pendidikan);	
		$this->load->view('master/tholabah/refresh', $data);
		
	}
	
}